{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['♥A', '♥2', '♥3', '♥4', '♥5', '♥6', '♥7', '♥8', '♥9', '♥10', '♥J', '♥Q', '♥K', '♠A', '♠2', '♠3', '♠4', '♠5', '♠6', '♠7', '♠8', '♠9', '♠10', '♠J', '♠Q', '♠K', '♦A', '♦2', '♦3', '♦4', '♦5', '♦6', '♦7', '♦8', '♦9', '♦10', '♦J', '♦Q', '♦K', '❀A', '❀2', '❀3', '❀4', '❀5', '❀6', '❀7', '❀8', '❀9', '❀10', '❀J', '❀Q', '❀K']\n"
     ]
    }
   ],
   "source": [
    "# pickle库\n",
    "# 帮你把数据存入，读取出来文件  \n",
    "\n",
    "# r w  a\n",
    "# rb wb ab\n",
    "\n",
    "\n",
    "import pickle\n",
    "\n",
    "a = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']\n",
    "b = ['♥','♠','♦','❀']\n",
    "ls = [x+y for x in b for y in a ]\n",
    "print(ls)\n",
    "f=open(\"d:\\\\crads.dat\",\"wb\")\n",
    "# 把列表直接用二进制数据保存起来\n",
    "pickle.dump(ls,f)\n",
    "f.close()\n",
    "\n",
    "# for x in b:\n",
    "    # for y in a:\n",
    "        # print(x+y)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['♥A', '♥2', '♥3', '♥4', '♥5', '♥6', '♥7', '♥8', '♥9', '♥10', '♥J', '♥Q', '♥K', '♠A', '♠2', '♠3', '♠4', '♠5', '♠6', '♠7', '♠8', '♠9', '♠10', '♠J', '♠Q', '♠K', '♦A', '♦2', '♦3', '♦4', '♦5', '♦6', '♦7', '♦8', '♦9', '♦10', '♦J', '♦Q', '♦K', '❀A', '❀2', '❀3', '❀4', '❀5', '❀6', '❀7', '❀8', '❀9', '❀10', '❀J', '❀Q', '❀K']\n"
     ]
    }
   ],
   "source": [
    "# 读取内容\n",
    "\n",
    "f=open(\"d:\\\\crads.dat\",\"rb\")\n",
    "# 从二进制数据中读取出来还原成列表\n",
    "ls2 = pickle.load(f)\n",
    "print(ls2)\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
